﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using DomainDriver.CommonUtilities.Enums;
using DomainDriver.DomainModeling.DataProviders;
using DomainDriver.DomainModeling.GenericUnitTesting.Repositories;
using AutomotivePricingModel.Dealers;

namespace AutomotivePricingModel.UnitTests.Repositories
{
    [TestFixture(new object[] { DataSourcePersistenceType.None })]
    [TestFixture(new object[] { DataSourcePersistenceType.File })]
    [TestFixture(new object[] { DataSourcePersistenceType.Database })]
    public class DealerRepositoryTests : RepositoryTestFixture<AutomotivePricingDomainModel, Guid, Dealer>
    {
        protected Guid m_Brand1Id = Guid.NewGuid();
        protected Guid m_Brand2Id = Guid.NewGuid();
        protected Guid m_Brand3Id = Guid.NewGuid();
        protected Guid m_Vehicle1Id = Guid.NewGuid();
        protected int m_Vehicle1OriginalValue = 5;
        protected int m_Vehicle1UpdatedValue = 8;
        protected Guid m_Vehicle2Id = Guid.NewGuid();
        protected int m_Vehicle2Value = 6;
        protected Guid m_Vehicle3Id = Guid.NewGuid();
        protected int m_Vehicle3Value = 3;

        public DealerRepositoryTests(DataSourcePersistenceType persistenceType)
            : base(persistenceType)
        {
            // do nothing
        }

        protected override AutomotivePricingDomainModel CreateDomainModel(DataSourcePersistenceType persistenceType, bool buildModelWithConstraints)
        {
            AutomotivePricingDomainModel model = new AutomotivePricingDomainModel(persistenceType, buildModelWithConstraints);
            return model;
        }

        protected override Dealer CreateDomainObject()
        {
            Dealer domainObject = new Dealer();
            domainObject.Name = domainObject.Key.ToString();

            domainObject.AddBrand(m_Brand1Id);
            domainObject.AddBrand(m_Brand2Id);

            domainObject.SetNumberOfVehiclesInStock(m_Vehicle1Id, m_Vehicle1OriginalValue);
            domainObject.SetNumberOfVehiclesInStock(m_Vehicle2Id, m_Vehicle2Value);

            return domainObject;
        }

        protected override void UpdateDomainObject(Dealer domainObject, ref bool objectCanBeUpdated)
        {
            objectCanBeUpdated = true;
            domainObject.Name += " UPDATED";

            domainObject.RemoveBrand(m_Brand2Id);
            domainObject.AddBrand(m_Brand3Id);

            domainObject.SetNumberOfVehiclesInStock(m_Vehicle1Id, m_Vehicle1UpdatedValue);
            domainObject.RemoveVehicleFromStock(m_Vehicle2Id);
            domainObject.SetNumberOfVehiclesInStock(m_Vehicle3Id, m_Vehicle3Value);
        }
    }
}